/*
 * Point3D.java
 *
 * Created on 4 de Dezembro de 2007, 10:55
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package mathematics;

/**
 *
 * @author rafaelbuck
 */
public final class Point3D
{

    /** Creates a new instance of Point3D */
    public Point3D()
    {
    }

    /** Creates a new instance of Point3D */
    public Point3D(Point3D p)
    {
        x = p.x;
        y = p.y;
        z = p.z;
    }

    /** Creates a new instance of Point3D */
    public Point3D(float xx, float yy, float zz)
    {
        x = xx;
        y = yy;
        z = zz;
    }

    public void scale(float f)
    {
        if(f != 1.0F)
        {
            x *= f;
            y *= f;
            z *= f;
        }
    }

    public void add(Vector3D v)
    {
        x += v.x;
        y += v.y;
        z += v.z;
    }

    public Point3D plus(Vector3D v)
    {
        Point3D ret = new Point3D(this);
        ret.add(v);
        return ret;
    }

    public void sub(Vector3D v)
    {
        x -= v.x;
        y -= v.y;
        z -= v.z;
    }

    public Point3D minus(Vector3D v)
    {
        Point3D ret = new Point3D(this);
        ret.sub(v);
        return ret;
    }

    public Vector3D minus(Point3D p)
    {
        Vector3D ret = new Vector3D(this);
        ret.sub(new Vector3D(p));
        return ret;
    }

    public boolean equals(Point3D p)
    {
        return p.x == x && p.y == y && p.z == z;
    }

    public String toString()
    {
        return new String((new StringBuffer()).append("[").append(x).append(",").append(y).append(",").append(z).append("]"));
    }

    public float x;
    public float y;
    public float z;
}